package num268;

/**
 * 268. 丢失的数字
 * 题目：https://leetcode-cn.com/problems/missing-number/
 * 三叶姐题解:  * 三叶姐题解: https://leetcode-cn.com/problems/ugly-number/solution/gong-shui-san-xie-jian-dan-de-fen-qing-k-dlvg/
 * <p>
 * 作差法
 */
class Solution4 {
    public int missingNumber(int[] nums) {
        int n = nums.length;
        int cur = 0, sum = n * (n + 1) / 2;
        for (int i : nums) {
            cur += i;
        }
        return sum - cur;
    }

    public static void main(String[] args) {
        new Solution4().missingNumber(new int[]{3, 0, 2});
    }
}
